package com.example.k12.utlis

import com.blankj.utilcode.util.SPUtils
import com.example.k12.bean.DeviceInfo
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

class AppConfig private constructor() {

    private object Holder {
        val INSTANCE = AppConfig()
    }

    companion object {
        val instance: AppConfig by lazy { Holder.INSTANCE }
    }

    // 用户相关
    var token: String = ""
    var deviceId: String = "695189"
    //wxPay
    var rawdata: String = ""

    var deviceInfo: DeviceInfo? = null
    var authInfo: String? = null

    // 清除所有配置
    fun clearAll() {
        token = ""
        rawdata = ""
    }

    /**
     * 判断今日是否同步过学校学生信息
     */
    fun isToday(): Boolean {
        val timestamp = SPUtils.getInstance().getLong(KeyManager.KEY_SYNC_TIME, 0L)
        val sdf = SimpleDateFormat("yyyyMMdd", Locale.getDefault())
        val todayString = sdf.format(Date())
        val dateString = sdf.format(Date(timestamp))
        return todayString == dateString
    }
}
